package com.ss.android.article.base.feature.f;

import android.content.Context;
import android.support.annotation.DrawableRes;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.ImageView;

import com.bytedance.common.utility.UIUtils;
import com.ss.android.article.base.feature.f.c.a;
import com.ss.android.article.browser.R;

public final class bb extends a {
    public interface b$a {
        void c();
    }

    SurfaceView a;
    View b;
    b$a c;
    private ImageView j;
    private boolean k;
    private View l;
    private Runnable m;

    public bb(Context arg2, b$a arg3, com.ss.android.article.base.feature.f.b.b arg4) {
        super(arg2, arg4);
        this.k = false;
        this.c = arg3;
        this.m = new cc(this);
    }

    public final void a(boolean arg4) {
        Context v0 = this.d();
        if(this.d() != null) {
            UIUtils.setVisibility(this.l, 8);
            if(arg4) {
                this.b.setBackgroundColor(v0.getResources().getColor(com.ss.android.article.browser.R.color.video_playerbg_color));
            }
            else {
                this.b.setBackgroundDrawable(null);
            }

            UIUtils.setVisibility(this.b, 0);
        }
    }

    public final void a(@DrawableRes int arg2) {
        this.j.setImageResource(arg2);
    }

    public final void a() {
        this.b();
        UIUtils.setVisibility(this.l, 8);
        this.k = false;
    }

    public final void a(View arg3) {
        this.a = arg3.findViewById(com.ss.android.article.browser.R.id.video_surface);
        SurfaceHolder v0 = this.a.getHolder();
        if(v0 != null) {
            ((a)this).h = v0;
            v0.setFormat(-3);
            v0.addCallback(new com.ss.android.article.base.feature.f.c.b(((a)this)));
        }

        this.b = arg3.findViewById(com.ss.android.article.browser.R.id.video_layer_loading);
        this.l = arg3.findViewById(com.ss.android.article.browser.R.id.video_layer_controll);
        this.j = this.l.findViewById(com.ss.android.article.browser.R.id.video_laye_btn);
        this.j.setOnClickListener(new d(this));
    }

    public final boolean a(MotionEvent arg6) {
        switch(arg6.getAction()) {
            case 0: {
                if(this.k) {
                    this.a();
                    break;
                }

                if(UIUtils.isVisible(this.b)) {
                    return true;
                }

                this.b();
                UIUtils.setVisibility(this.l, 0);
                int v0 = this.d.d() ? R.drawable.media_pause_icon_selector : R.drawable.play_movebar_textpage;
                this.a(v0);
                this.k = true;
                break;
            }
            case 1: {
                if(!this.k) {
                    return true;
                }

                if(!this.d.d()) {
                    return true;
                }

                this.l.postDelayed(this.m, 2000);
                break;
            }
            case 3: {
                this.a();
                break;
            }
        }

        return true;
    }

    public final void b() {
        if(this.l != null && this.m != null) {
            this.l.removeCallbacks(this.m);
        }
    }
}

